package com.example.demo2.config;

import com.example.demo2.util.RabbitMqUtils;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfigation {
    //创建交换机 发布订阅模式
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange(RabbitMqUtils.ORDER_EXCHANGE,true,false);
    }
    //创建队列
    @Bean
    public Queue weixin(){
        return new Queue("weixin",true);
    }
    @Bean
    public Queue email(){
        return new Queue("email",true);
    }
    @Bean
    public Queue qq(){
        return new Queue("qq",true);
    }
    //队列绑定交换机
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(weixin()).to(fanoutExchange());
    }
    @Bean
    public Binding binding1(){
        return BindingBuilder.bind(email()).to(fanoutExchange());
    }
    @Bean
    public Binding binding2(){
        return BindingBuilder.bind(qq()).to(fanoutExchange());
    }
}
